package adv10;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ReadXml {

	public static void main(String[] args) throws DocumentException {
		// TODO 自动生成的方法存根
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new java.io.File("courses.xml"));
		Element root = doc.getRootElement();
		System.out.println("根节点的名称是" + root.getName());
		List<Element> list = root.selectNodes("course");
		System.out.println(list.size());
		for (Element m : list) {
			// m.getName()==course
			String no = m.attributeValue("no");
			System.out.println("course no=" + no);
			String u = m.attributeValue("unit");
			System.out.println(u);
			// List<Element> l2 = m.selectNodes("name");
			// String name = l2.get(0).getText();
			String ename = m.selectSingleNode("name").getText();
			String time = m.selectSingleNode("time").getText();
			String target = m.selectSingleNode("target").getText();
			String content = m.selectSingleNode("content").getText();
			System.out.println(ename.trim() + "," + time + "," + target + ","
					+ content);
		}
	}

}
